// const app = getApp<AppOption>()
// import dayjs from "dayjs";
import dayjs from "dayjs";
// import { nanoid } from 'nanoid'

// chart 图
// const F2 = require('@antv/f2-wx');
// import { createElement } from "@antv/f2";
import { chartData } from "../../utils/charts";

// import { jsx as _jsx } from "@antv/f-engine/jsx-runtime";

Page<IData, IPage>({
  data: {
    name: "home page",
    users: [],
    xhrData: [],
    tempData: {
      name: "tempData --- name",
      size: "default",
      count: 121,
    },
    onRenderChart: () => {},
    chartData: chartData,
    // onRenderCanvas: () => {},
  },
  onLoad() {
    // console.log(this, "onLoad", this.data);
    const nowDate = dayjs().format("YYYY-MM-DD HH:mm:ss");
    this.setData({
      name: this.data.name + nowDate,
      // onRenderChart: () => { // 渲染数据
      //   return this.renderChart(this.data.chartData);
      // },
    });

    // const query = wx.createSelectorQuery()
    // const canvasID =  query.select('#column-chart')
    // console.log('query', query, canvasID);

    // const id = nanoid()
    // console.log('id', id)
  },

  onShow() {
    // tabBar 点击切换
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1,
      });
    }
    this.getUserData();
  },
  onReady() {},

  getUserData() {
    // 获取用户数据
    wx.request({
      url: "http://localhost:3535/user/getUser",
      data: {},
      method: "GET",
      header: {
        "content-type": "application/json;charset:utf-8;",
      },
      success: (res) => {
        const { code, data } = res.data as { code: number; data: any[] };
        if (code === 0) {
          this.setData({ xhrData: data });
        }
        // console.log(this.data.xhrData)
      },
    });
  },
  handleAddTemp() {
    this.setData({
      tempData: {
        ...this.data.tempData,
        count: this.data.tempData.count + 1,
      },
    });
  },
  handleTap1() {
    console.log("handleTap1");
  },
  handleTap2() {
    console.log("handleTap2");
  },
  handleTap3() {
    // console.log("handleTap3", this);
  },

  // renderChart(data) {
  //   // return _jsx(echarts.echarts1, {
  //   //   data: data,
  //   // });
  //   // 如果不使用 jsx, 用下面代码效果也是一样的
  //   // return createElement(inChart, {
  //   //   data: data,
  //   // });
  // }
});
